'''
https://leetcode.cn/problems/implement-queue-using-stacks/description/
'''


class MyQueue:

    def __init__(self):
        self.stack = [[], []]

    # 返回(入栈(有元素的)，出栈(无元素的))
    def get_stack(self):
        return (self.stack[0], self.stack[1]) if self.stack[0] else (self.stack[1], self.stack[0])

    def push(self, x: int) -> None:
        in_stack, out_stack = self.get_stack()
        in_stack.append(x)

    def pop(self) -> int:
        in_stack, out_stack = self.get_stack()
        while in_stack:
            out_stack.append(in_stack.pop())
        res = out_stack.pop()
        while out_stack:
            in_stack.append(out_stack.pop())
        return res

    def peek(self) -> int:
        in_stack, out_stack = self.get_stack()
        while in_stack:
            out_stack.append(in_stack.pop())
        res = out_stack[-1]
        while out_stack:
            in_stack.append(out_stack.pop())
        return res

    def empty(self) -> bool:
        return (not self.stack[0]) and (not self.stack[1])


# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()